<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<!-- 引入 css -->
		<link href="css/style.css" rel="stylesheet">
		
		<!-- 引入 js -->
		<script src="js/wangEditor.min.js"></script>
		<script src="js/jquery-2.2.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/shortcut.js" type="text/javascript" charset="utf-8"></script>
		<div style="height: 50px;">Alt+Q,增加缩进，Alt+W:减少缩进</div>
		<div id="div1">
		    <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
		</div>
		<button id="submitText" type="button">提交文本</button>
		<button id="submitHtml" type="button">提交内容</button>
		<div id="msg" style="color:red"></div>
		<script src="js/http.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			
		    	
	    	const E = window.wangEditor
		    const editor = new E('#div1')
		    // 或者 const editor = new E( document.getElementById('div1') )
		    editor.config.height = 600;
		    editor.create()
		    
	    	var pid = localStorage.getItem("pid")
	    	var value = localStorage.getItem("value")
	    	editor.txt.html(value);
	    	
	    	shortcut.add("Alt+Q",function() {
				$("[data-title=缩进]").click();
				$(".w-e-icon-indent-increase").click();
			});
			shortcut.add("Alt+W",function() {
				$("[data-title=缩进]").click();
				$(".w-e-icon-indent-decrease").click();
			});
			shortcut.add("Alt+s",function() {
				$("#submitHtml").click();
			});
			
	    	
	    	document.getElementById("submitText").onclick = function(){
				data = {
						"label":editor.txt.text(),
						"pid":pid
					}
				$.ajax({
					type:"post",
					url:remoteIp+"/back/insert",
					async:true,
					contentType:"application/json",
					data:JSON.stringify(data),
					success:function(){
						$("#msg").text("操作成功！");
						setTimeout(function(){
							$("#msg").text("");
						},1000)
					}
				});
			}
	    	document.getElementById("submitHtml").onclick = function(){
				data = {
						"label":editor.txt.html(),
						"pid":pid
					}
				$.ajax({
					type:"post",
					url:remoteIp+"/back/insert",
					async:true,
					contentType:"application/json",
					data:JSON.stringify(data),
					success:function(){
						$("#msg").text("操作成功！");
						setTimeout(function(){
							$("#msg").text("");
						},1000)
					}
				});
			}
		    	
			
		</script>
	</body>

</html>